<?php
class loginControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
		
		
	}
	
	public function onDefault(){
		if(SHOPID){
			$this->gourl(APPTGYUAN."?m=index");
		}
		$this->smarty->display("login/login.html");
	}
	
	public function onSave(){
		$adminname=post('adminname','h');
		$row=M("tgyuan_admin")->selectRow(array("where"=>" adminname='".$adminname."' "));
		if($row && $row['password']==umd5(post('password').$row['salt'])){
			$_SESSION['sstgyuanadmin']=$row;
			$authcode=jiami($row['adminid']."|".umd5($row['password']));
			setcookie("tg_authcode",$authcode,time()+3600000,"/",DOMAIN);
			//处理推送相关
			M("apppush")->add("tgyuanadmin",$row);
			$this->goall("登录成功",0,0,APPTGYUAN."?m=iframe");
		}else{
			$this->goall("账户或者密码出错",1);
		}
	}
	
	public function onlogout(){
		$_SESSION['sstgyuanadmin']="";
		setcookie("tg_authcode","",time()-3999,"/",DOMAIN);	
		$this->goall("退出成功",0,0,APPTGYUAN."/index.php?m=login");
	}
	
	 
	
	public function onAdmin(){
		M("login")->checkAdminLogin();
		$id=get('id','i');
		$admin=M("tgyuan_admin")->selectRow(array("where"=>"shopid=".$id." "));
			
			$_SESSION['sstgyuanadmin']=$admin;
			
			$this->gourl(APPTGYUAN."?m=iframe"); 
	}
		
}
?>